package chapter1113;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PicDemo extends MyFrame{
    JButton button;
    int x2 = 50;
    int y2 = 50;

    public PicDemo() {
        button = new JButton("paint line");
        this.add(button);
        button.addActionListener(new ABC());
        this.setVisible(true);
    }

    @Override
    public void paint(Graphics g) {
        g.drawLine(100,100,x2,y2);

//        String picurl = "D:\\Mycode\\Java\\NJXZC_OOP2024\\chapter1113\\float.jpg";
//        Image image = Toolkit.getDefaultToolkit().getImage(picurl);
//        System.out.println(image);
//        g.drawImage(image,0,0,this);
    }

    public static void main(String[] args) {
        new PicDemo();
    }

    class ABC implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            repaint();
            y2+=10;
            x2-=10;
        }
    }

}
